package pers.qianyu.module.core.util;


import cn.hutool.http.useragent.*;
import pers.qianyu.module.core.domain.logging.vo.*;

/**
 * @author mizzle rain
 * @date 2020-11-03 13:37
 */
public class BrowserUtil {
    /**
     * 解析 UserAgent
     *
     * @param userAgent userAgent 字符串
     * @return 浏览器信息
     */
    public static UserAgentVO parseUserAgent(String userAgent) {
        UserAgent ua = UserAgentUtil.parse(userAgent);
        UserAgentVO userAgentVO = new UserAgentVO();
        userAgentVO.setMobile(ua.isMobile());
        userAgentVO.setBrowser(ua.getBrowser().toString());
        userAgentVO.setPlatform(ua.getPlatform().toString());
        userAgentVO.setOs(ua.getOs().toString());
        userAgentVO.setEngine(ua.getEngine().toString());
        userAgentVO.setVersion(ua.getVersion());
        userAgentVO.setEngineVersion(ua.getEngineVersion());
        return userAgentVO;
    }
}
